package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/">1309. 解码字母到整数映射</a>
 */
public class Solution1309 extends BaseSolution {

    public String freqAlphabets(String s) {
        StringBuilder sb = new StringBuilder();
        char[] origin = s.toCharArray();
        for (int i = origin.length - 1; i >= 0;) {
            if (origin[i] != '#') {
                sb.insert(0, (char) (origin[i] - '1' + 'a'));
                i--;
            } else {
                int ind = (origin[i - 2] - '0') * 10 + origin[i - 1] - '0';
                sb.insert(0, (char) (ind - 1 + 'a'));
                i -= 3;
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        Solution1309 solution = new Solution1309();
        System.out.println(solution.freqAlphabets("10#11#12"));
    }
}